<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>

<a href="https://gitee.com/oauth/authorize?client_id=dbc8569ae72fb51446f7fdccf07605a6809e887f5c5f242103df44b8fe552f94&redirect_uri=http://localhost:8080/callbackCode.do&response_type=code">用户昵称</a>
${nickName}  <img src="${avatarUrl}">


<form action="/list.do">
    楼盘名称<input name="name"><br>
    省份 <select name="provinceId"  onchange="getCity()">
    <option value="">请选择</option>
    <c:forEach items="${provinceList}" var="p">
        <option value="${p.id}">${p.name}</option>
    </c:forEach>
</select><br>
    城市<select name="cityId">
    <option value="">请选择</option>
</select><br>
    <input type="submit" value="查询"><br>   <a href="/addPage.do">添加</a>
    <table>
        <tr>
            <td>id</td>
            <td>名称</td>
            <td>地址</td>
            <td>省份</td>
            <td>城市</td>
            <td>图片</td>
        </tr>
        <c:forEach items="${pageInfo.list}" var="l">
            <tr>
                <td>${l.id}</td>
                <td>${l.name}</td>
                <td>${l.address}</td>
                <td>${l.provinceName}</td>
                <td>${l.cityName}</td>
                <td> <img  style="width: 50px;height: 50px;" src="${l.picUrl}"></td>
            </tr>
        </c:forEach>
    </table>
    <tr>
        <td> <button name="pageNum" value="1">首页</button></td>
        <td> <button name="pageNum" value="${pageInfo.prePage}">上页</button></td>
        <td> <button name="pageNum" value="${pageInfo.nextPage}">下页</button></td>
        <td> <button name="pageNum" value="${pageInfo.pages}">尾页</button></td>
    </tr>
</form>
<script>


    function getCity() {
        let provinceId = $('[name=provinceId]').val();

        $.ajax({
            url:'/getCity.do?provinceId=' + provinceId,
            success:function (data) {
                console.log(data)

                $('[name=cityId]').empty();

                $('[name=cityId]').append(
                    '<option value="">请选择</option>'
                )
                for (let i = 0; i < data.length; i++) {
                    let id = data[i].id;
                    let name = data[i].name;

                    $('[name=cityId]').append(
                        '<option value='+id+'>'+name+'</option>'
                    )
                }

            }

        })


    }


</script>

</body>
</html>